package com.pan.test.socket.example03;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class StreamTools {
    public static byte[] toByteArr(InputStream inputStream) throws IOException {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        int len;
        byte buf[] = new byte[1024];
        while ((len = inputStream.read(buf))!=-1){
            byteArrayOutputStream.write(buf,0,len);
        }
        byte[] result = byteArrayOutputStream.toByteArray();
        byteArrayOutputStream.close();
        return result;
    }
}
